<template>
	<view class="wrap">
		<js-error mode="bottom" ref="jsError"></js-error>
		<view class="action bg-white "
			style="padding: 15px 0 0 10px;font-size: 20px;align-items: center;display: flex;">
			<u-icon name="/static/image/invcode.png" size="80"></u-icon>
			<text class="cuIcon-titles text-bold">废旧物资信息</text>
		</view>

		<u-form class="form bg-white" :model="model" ref="uForm" label-position="left">
			<u-form-item label="车次:" prop="djNo" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder=" " v-model="model.djNo" type="text" :disabled="true" di maxlength="64"></u-input>
			</u-form-item>
			<u-form-item label="车牌号:" prop="carNo" label-width="200" required :label-style="{'font-weight':'bold'}">
				<!-- <u-input placeholder="请输入" v-model="model.carNo" type="text" di maxlength="64"></u-input> -->
				<xm-cell special label="" :value="model.carNo" @show="showKeyboard('xmKeyboard')"></xm-cell>
				<!-- 虚拟键盘载体 -->
				<xm-keyboard-v2 ref="xmKeyboard" @confirm="carNoconfirm"></xm-keyboard-v2>
			</u-form-item>
			<u-form-item label="计划日期" prop="time" label-width="200" required :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入" v-model="model.planDate" type="select" :select-open="pickerTime"
					@click="pickerTime = true"></u-input>
			</u-form-item>
			<u-picker mode="time" v-model="pickerTime" @confirm="timeConfirm" :params="params"></u-picker>
			<u-form-item label="司机:" prop="cdriver" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入" v-model="model.cdriver" type="text" di maxlength="64"></u-input>
			</u-form-item>
			
			<u-form-item label="司机电话:" prop="driverPhone" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入" v-model="model.driverPhone" type="text" di maxlength="64"></u-input>
			</u-form-item>
			
			<!-- <u-form-item label="运输单位:" prop="testCarVen" label-width="200" required
				:label-style="{'font-weight':'bold'}">
				<js-select v-model="model.carVenCode" :showFilter="true" :items="carVenSelectList" placeholder="请选择" :tree="true"
					:label-value="model.carVenName" @label-input="model.carVenName = $event"></js-select>
			</u-form-item> -->
			<u-form-item label="备注:" prop="remarks" label-width="200" :label-style="{'font-weight':'bold'}">
				<u-input placeholder="请输入" v-model="model.remarks" type="text" di maxlength="64"></u-input>
			</u-form-item>
		</u-form>
		<!-- <view class="action bg-white "  v-if="query.id"
			style="font-size: 20px;align-items: center;display: flex;padding: 0 0 10px 10px;">
			<u-icon name="/static/image/detail.png" size="80"></u-icon>
			<text class="cuIcon-titles text-bold">废旧物资明细</text>
		</view>
		<view style="padding: 10px;">
			<view v-for="(item,index) in children" class="cu-item shadow " style="position: relative;" :key="index">
				<view class="cu-form-group" style="display: flex;justify-content: space-between;">
					<view
						style=" display: inline-block;padding: 5px;background: #3E97B0;color: #fff;min-width: 40px;text-align: center;font-style: italic;font-weight: bold">
						{{ index + 1 }}
					</view>
					<view style="display: flex;align-items: center;">
							<u-icon name="/static/image/edit.png" @click="editDetail(item)"   size="70"></u-icon>
						
							<text style="font-size: 35px;margin-left: 20px;" class="cuIcon-deletefill text-sl text-red"
								@tap="delDetail(item.id)"></text>
					</view>
				</view>
				<view class="cu-form-group text-bold text-red">
					<view class="title">废旧物资：</view>
					<view style="flex: 1;"> {{ item.invName|| ""  }}</view>
				</view>
				<view class="cu-form-group">
					<view class="title">客户名称：</view>
					<view style="flex: 1;"> {{ item.cusName|| ""  }}
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">净重：</view>
					<view style="flex: 1;"> {{ item.jzWeight|| ""  }} </view>
				</view>
				<view class="cu-form-group">
					<view class="title">备注：</view>
					<view style="flex: 1;"> {{ item.remarks|| ""  }} </view>
				</view>
				
			</view>
	</view> -->
	
	<!-- <view class="form-footer" @click="GoaddChild()" v-if="query.id">
		<view class="btn-plus">
			<u-icon name="plus-circle" size="90" color="#3E97B0"></u-icon>
		</view>
	</view> -->
	<view style="height: 70px;"></view>
	<view class=" flex cu-bar tabbar bg-white foot cu-modal-footer">
		<button class="cu-btn  bg-confirm lg  " @click="submit">保存</button>
		<button class="cu-btn  lines-red lg margin-left" @click="cancel">关闭</button>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true
				},
				model: {
					// id:'',
					// carNo:'',
					// planDate:'',
					// cdriver:'',
					// driverPhone:'',
					// carVenCode:'',
					// carVenName:'',
					// remarks:'',
				},
				//主表id
				query: {
					id: '',
				},
				//子表id
				querys: {
					id: '',
				},
				children: [],
				carVenSelectList: [],
				pickerTime: false, //控制日期显示
			}
		},
		onLoad(params) {
			if(params.id){
				this.query.id = params.id
				this.$u.api.mf.fjform(this.query).then(res => {
					this.model = res.mfCarplanFjH;
				});
			}
			// uni.$on('refreshData', () => {
			// 	this.loadList();
			// })
		},
		onShow() {},
		onReady() {
			// 运输单位数据
			this.$u.api.carVen.treeData().then(res => {
				this.carVenSelectList = res;
			});
		},
		methods: {
			carNoconfirm(v){
				this.model.carNo = v;
				this.$forceUpdate()
			},
			showKeyboard(ref){
				this.$refs[ref].toShow(this.model.carNo)
			},
			cancel() {
				// uni.$emit('refreshData');
				uni.navigateBack({
					delta: 1,
				})
			},
			toFindDetail(model) {
				const that = this
				uni.navigateTo({
					url: '/pages/mf/fh/fhDetailList?hid=' + model.id,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						Filter(data) {

						}
					},
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						// res.eventChannel.emit('initfilter', that.filter)
					}
				})
			},
			toAddDetail(model) {
				const that = this
				uni.navigateTo({
					url: '/pages/mf/fh/fhHwAdd?hid=' + model.id,
					events: {
						// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
						Filter(data) {

						}
					},
					success: function(res) {
						// 通过eventChannel向被打开页面传送数据
						// res.eventChannel.emit('initfilter', that.filter)
					}
				})
			},
			delDetail(id) {
				this.querys.id = id;
				uni.showModal({
					title: '删除提示',
					content: '是否删除此详情？',
					confirmColor: '#F54E40',
					success: (res) => {
						if (!res.confirm) {
							this.isdisabled = true
							return false;
						}
						this.$u.api.mf.fjdelDetail(this.querys).then(res => {
							if (res.result=="true") {
								this.$u.toast("删除成功！");
							} else {
								this.$refs.jsError.showError('',res.message,'error');
							}
							this.querys.id = ''
							this.loadList();
						})
					}
				})
			},
			editDetail(item){
				const that=this
				uni.navigateTo({
				  url: '/pages/mf/fjwz/detailForm?model='+JSON.stringify(item),
				  events: {
				    // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
				    Filter(data) {
						
				    }
				  },
				  success: function(res) {
				    // 通过eventChannel向被打开页面传送数据
				    // res.eventChannel.emit('initfilter', that.filter)
				  }
				})
			},
			loadList() {
				this.$u.api.mf.fjfindList(this.query).then(res => {
					if (!res.list || res.list.length == 0) {
						return;
					}
					var data = res.list[0];
					this.model = data;
					this.children = data.mfCarplanFjCList;
				})
			},
			GoaddChild() {
				if (this.model.id == null || this.model.id == '') {
					this.$refs.jsError.showError('','请先保存废旧物资信息！','error');
					return;
				} else {
					const that = this;
					uni.navigateTo({
						url: '/pages/mf/fjwz/detailForm?model=' + JSON.stringify({id:this.model.id}),
						events: {
							// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
							Filter(data) {
								console.log(data)
							}
						},
						success: function(res) {
							// 通过eventChannel向被打开页面传送数据
							//res.eventChannel.emit('initfilter', that.queryData)
						}
					})
				}
			},
			timeConfirm(e) {
				this.model.planDate = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ":" + e.minute + ":" + e
					.second;
			},
			submit(data, callback) {
				if(this.model.carNo == null || this.model.carNo == ''){
					this.$refs.jsError.showError('','请正确填入车牌号！','error');
					return;
				}else if(this.model.planDate == null || this.model.planDate == ''){
					this.$refs.jsError.showError('','请正确选择计划到货日期！','error');
					return;
				}else{
					// var data = {
					// mfCarplanFjH: JSON.stringify(this.model),
					// useStatus: 1
					// };
					var data = this.model;
					this.$u.api.mf.fjsaveApp(data).then(res => {
						if(res.result == 'true'){
							this.$u.toast(res.message);
							uni.navigateBack({
								delta: 1
							})
						}else{
							this.$refs.jsError.showError('',res.message,'error');
						}
					});
				}
			},
		}
	}
</script>
<style lang="less">
	/* .footer {
	position: fixed;
	bottom: 0;
	right:0;
	width: 100%;
	line-height: var(--footer-height);
	background: #ffffff;
	color: #ffffff;
} */
	.btn-plus {
		position: fixed;
		bottom: 260rpx;
		right: 40rpx;
		z-index: 2;
		opacity: 0.6;
	}

	.btn-plus:hover {
		opacity: 1;
	}

	.add {
		position: absolute;
		right: 130rpx;
		top: 0;
		margin-right: 0;
	}

	.upload {
		position: absolute;
		right: 65rpx;
		top: 0;
		margin-right: 0;
	}

	.rights {
		position: absolute;
		/* display: inline-block; */
		right: 0;
		top: 0;
		margin-right: 0;
		/* width: 100%; */

	}

	.cu-bar {
		min-height: 80px;
	}

	.cu-btn {
		font-size: 16px;
		height: 40px;
	}

	.foot {
		background: #fff;
	}

	.cu-item {
		flex-wrap: wrap;
		padding: 8px 15px !important;
	}

	.title {
		width: 210rpx;
	}

	.cu-modal-slot {
		margin: 42rpx 32rpx 20rpx 32rpx;
		height: 100vh;
		position: relative;
	}

	.cu-modal-header {
		font-size: 38rpx;
		color: #3d3d3d;
		line-height: 40rpx;
		text-align: left;
		font-weight: 500;
	}

	.button {
		font-size: 32rpx;
		color: #666666;
		line-height: 40rpx;
		padding: 12rpx 40rpx;
		margin-bottom: 20rpx;
		background: #e2e2e2;
		border-radius: 180rpx;
	}

	.button:hover {
		background: #3e97b0;
		color: #ffffff;
	}

	.cu-modal-search-title {
		margin: 32rpx 0rpx 20rpx 0rpx;
		text-align: left;
		font-size: 32rpx;
		color: #999999;
		line-height: 40rpx;
	}

	.cu-dialog {
		background: #ffffff;
	}

	.cu-modal-footer {
		padding: 32rpx 32rpx !important;
		width: 100%;

		.cu-btn {
			width: 50%;
		}
	}

	.bg-confirm {
		background: #3e97b0;
		color: #ffffff;
	}
</style>